package com.voilet.interview.rx.operator.create;

import android.util.Log;

import com.voilet.interview.rx.operator.absOperator;

import java.util.concurrent.TimeUnit;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * Created by kan212 on 2019/4/10.
 */

public class timer implements absOperator {
    @Override
    public void test() {
        // 该例子 = 延迟2s后，发送一个long类型数值
        Observable.timer(2, TimeUnit.SECONDS)
                .subscribe(new Observer<Long>() {
                    @Override
                    public void onSubscribe(Disposable d) {
                        Log.d(TAG, "开始采用subscribe连接");
                    }

                    @Override
                    public void onNext(Long value) {
                        Log.d(TAG, "接收到了事件"+ value  );
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.d(TAG, "对Error事件作出响应");
                    }

                    @Override
                    public void onComplete() {
                        Log.d(TAG, "对Complete事件作出响应");
                    }

                });

    // 注：timer操作符默认运行在一个新线程上
    // 也可自定义线程调度器（第3个参数）：timer(long,TimeUnit,Scheduler)
    }

    @Override
    public void test2() {

    }
}
